package com.auth.config.response;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

/**
 * json序列号实现类
 * @author: hw
 * @date: 2020/12/23 20:37
 */
public class CustomOauthExceptionSerializer extends StdSerializer<CustomOauthException> {

    protected CustomOauthExceptionSerializer() {
        super(CustomOauthException.class);
    }


    /**
     *  自定义返回参数
     * @param value
     * @param gen
     * @param provider
     * @throws IOException
     */
    @Override
    public void serialize(CustomOauthException value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStartObject();
        gen.writeObjectField("result", -1);
        gen.writeStringField("resultCode", value.getMessage());
        gen.writeStringField("error", value.getErrorCode());
        gen.writeEndObject();
    }
}
